package mario;

import thread.StaticValue;

import java.awt.image.BufferedImage;
//https://blog.csdn.net/loveliveluo/article/details/125445852
public class Mario implements Runnable {
    //    用于表示横坐标
    private int x;
    //    用于表示纵坐标
    private int y;
    //    用于显示当前的状态
    private String status;
    //    用于显示当前状态对应的图像
    private BufferedImage show = null;
    //    用来实现马里奥的动作
    private Thread thread = null;
    //    马里奥的移动速度
    private int xSpeed;
    //    马里奥的跳跃速度
    private int ySpeed;
    //定义一个索引
    private int index;

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public BufferedImage getShow() {
        return show;
    }

    public void setShow(BufferedImage show) {
        this.show = show;
    }

    public Mario() {

    }

    public Mario(int x, int y) {
        this.x = x;
        this.y = y;
        show = StaticValue.stand_R;
        this.status = "stand--right";
        thread = new Thread(this);
        thread.start();
    }

    public void rightMove() {
        xSpeed = 5;
        status = "move--right";
    }


    public void rightStop() {
        xSpeed = 0;
        status = "stop--right";
    }


    public void leftMove() {
        xSpeed = -5;
        status = "move--left";
    }

    public void leftStop() {
        xSpeed = 0;
        status = "stop--left";
    }

    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(50);
                System.out.println(index);
                if (status.contains("move")) {
                    switch (index) {
                        case 0:
                            index = 1;
                            break;
                        case 1:
                            index = 2;
                            break;
                        case 2:
                            index = 0;
                            break;
                    }
                }
                if (status.equals("move--right")){
                    show = StaticValue.run_R.get(index);
                }
                if (status.equals("move--left")){
                    show = StaticValue.run_L.get(index);
                }
                x += xSpeed;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }
}
